///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////

#include "definitions.h"
#include <list>
#include "commands.h"
#include "commandTable.h"
#include "character.h"
#include "world.h"
#include "stringutil.h"
#include "split.h"
#include "timestamp.h"
#include "vEditHandler.h"

using namespace std;

// rCommand definitions
// (Keep in alphabetical order... it's MUCH easier)

vCmdAdd::vCmdAdd() {
	SetName( "+" );
	SetLevel( 1 );
	SetEnabled( true );
}

bool vCmdAdd::Execute( Character* c, const string& args ) {
	vEditHandler* vh = vEditList::Instance()[ c->getName() ];

	vh->addLine( args );

	c->Send( vh->editWindow() );

	return true;
}

vCmdExit::vCmdExit() {
	SetName( "exit" );
	SetLevel( 1 );
	SetEnabled( true );
}

bool vCmdExit::Execute( Character* c, const string& args ) {

	c->setVEdit( false );
	vEditList::Instance().getList().remove( vEditList::Instance()[ c->getName() ] );

	return true;
}

vCmdHelp::vCmdHelp() {
	SetName( "help" );
	SetLevel( 1 );
	SetEnabled( true );
}

bool vCmdHelp::Execute( Character* c, const string& args ) {
	std::string buf;

	buf = "{CSymphony Text Editor commands{x\n\r\n\r";
	buf << " +  {w[number]{x {w[line]{x  appends text\n\r";
	buf << " -  {w[number]{x         removes a line\n\r";
	buf << " il {w[number]{x {W<line>{x  inserts text\n\r";
	buf << " rl {W<number>{x {W<line>{x  replaces a given line of text\n\r";
	buf << " exit                quits Symphony Text Editor\n\r";

	c->Send( buf );

	return true;
}

vCmdInsert::vCmdInsert() {
	SetName( "il" );
	SetLevel( 1 );
	SetEnabled( true );
}

bool vCmdInsert::Execute( Character* c, const string& args ) {
	vEditHandler* vh = vEditList::Instance()[ c->getName() ];

	vh->insertLine( args );

	c->Send( vh->editWindow() );

	return true;
}

vCmdRemove::vCmdRemove() {
	SetName( "-" );
	SetLevel( 1 );
	SetEnabled( true );
}

bool vCmdRemove::Execute( Character* c, const string& args ) {
	vEditHandler* vh = vEditList::Instance()[ c->getName() ];

	vh->removeLine( args );

	c->Send( vh->editWindow() );

	return true;
}

vCmdReplace::vCmdReplace() {
	SetName( "rl" );
	SetLevel( 1 );
	SetEnabled( true );
}

bool vCmdReplace::Execute( Character* c, const string& args ) {
	vEditHandler* vh = vEditList::Instance()[ c->getName() ];

	vh->replaceLine( args );

	c->Send( vh->editWindow() );

	return true;
}
